package com.origin.multimedia.music

import android.content.Context
import android.media.MediaPlayer
import android.net.Uri
import android.util.Log



class MusicPlayer private constructor(c: Context) {
    var mContext: Context = c;

    companion object {
        @Volatile
        var instance: MusicPlayer? = null

        fun getInstance(c: Context): MusicPlayer {
            if (instance == null) {
                synchronized(MusicPlayer::class) {
                    if (instance == null) {
                        instance = MusicPlayer(c)
                    }
                }
            }
            return instance!!
        }
    }


    private val TAG = this.javaClass.simpleName
    val mPlayer: MediaPlayer by lazy {
        MediaPlayer()
    }



    fun play(url: String) {
        mPlayer.setDataSource(url)
        mPlayer.prepareAsync()
        mPlayer.setOnPreparedListener(object : MediaPlayer.OnPreparedListener {
            override fun onPrepared(p0: MediaPlayer?) {
                Log.e(TAG, "准备完成")
            }

        })

    }


    fun start() {
        mPlayer.start()
    }


}